const { parse } = require("../utils/file_tool");
const { exec_shell } = require("../utils/shell_tool");
const { BaseCommand } = require("./base");

class UpdatingRevisionCommand extends BaseCommand {
    async execute() {
        const currentInfo = await parse(
            await exec_shell({
                cmd: "svn info",
                cwd: this.selfData.cwd,
                capture_stdout: true,
            }),
            "yaml",
        );
        let comingUpdates = await exec_shell({
            cmd: `svn mergeinfo --show-revs eligible ${currentInfo.URL}`,
            cwd: this.selfData.cwd,
            capture_stdout: true,
        });
        comingUpdates = comingUpdates
            .split(/[\r\n]{1,2}/)
            .map((v) => v.substr(1))
            .filter((v) => v && v !== currentInfo.Revision);
        return comingUpdates;
    }
}

module.exports = {
    UpdatingRevisionCommand,
};
